<template>
  <div class="comment-list">
    <!-- 用户评论 start -->
    <div class="comment-item" v-for="(item,index) in comments" :key="index">
      <div class="user-img">
        <img :src="`../imgs/users/${item.userImg}`" />
      </div>
      <div class="user-info">
        <div class="user-name">
          <span>{{ item.name }}</span>
          <film-source :source="item.source"></film-source>
        </div>
        <div class="user-time">{{ item.time }}</div>
      </div>
      <div class="user-conent">
          {{ item.msg }}
      </div>
    </div>
    <!-- 用户评论 end -->
  </div>
</template>

<script>
export default {
  data() {
    return {
        comments:[]
    };
  },
  created() {
      this.loadCommentsData();
  },
  methods: {
      loadCommentsData(){
          this.$api.loadCommentsByFilmId({
              filmId:this.$route.params.filmId
          }).then(res => {
            //   console.log(res);
            this.comments = res
          })
      }
  },
  beforeMount() {
    // 监听更新评论的事件，重新加载数据
    this.$root.$on('update:comment',this.loadCommentsData) 
  },
};
</script>

<style lang="less" scoped>
</style>